<?php
namespace Shop\Api;
use Common\Api\Api;
use Shop\Model\ShoppingCartModel;

/**
 * Created by PhpStorm.
 * User: an
 * Date: 2015/8/20
 * Time: 17:38
 */
class ShoppingCartApi extends  Api{
    const ADD="Shop/ShoppingCart/add";

    const QUERY="Shop/ShoppingCart/query";
	
	const QUERY_NO_PAGING="Shop/ShoppingCart/queryNoPaging";

    const SAVE_BY_ID="Shop/ShoppingCart/saveById";

    const SAVE="Shop/ShoppingCart/save";

    const GET_INFO="Shop/ShoppingCart/getInfo";

    const DELETE="Shop/ShoppingCart/delete";

    const COUNT = "Shop/ShoppingCart/count";

    const QUERY_WITH_STORE_INFO = "Shop/ShoppingCart/queryWithStoreInfo";


    protected  function _init(){
        $this->model=new ShoppingCartModel();
    }

    /**
     * 查询左链接包含店铺信息
     * @param $map
     * @return array
     */
    public function queryWithStoreInfo($map){

        if(isset($map['uid'])){
            $map['cart.uid'] = $map['uid'];
            unset($map['uid']);
        }
        if(isset($map['id'])){
            $map['cart.id'] = $map['id'];
            unset($map['id']);
        }

        $result = $this->model->field('p.name,p.dt_goods_unit,p.dt_origin_country,store.uid as store_creator,cart.id,cart.uid,cart.store_id,cart.p_id,cart.sku_id,cart.sku_desc,cart.icon_url,cart.count,cart.name,cart.express,cart.price,cart.ori_price,cart.psku_id,cart.weight,cart.taxrate,store.service_phone,store.weixin_number,store.logo as store_logo,store.longitude,store.latitude,store.exp as store_exp')
            ->alias("cart")->join("LEFT JOIN __STORE__ as store on store.id = cart.store_id")->join("LEFT JOIN __PRODUCT__ as p on p.id = cart.p_id")->where($map)->select();


        if($result === false){
            return $this->apiReturnErr($this->model->getDbError());
        }else{
            return $this->apiReturnSuc($result);
        }

    }


}
